package com.yingying.service;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yingying.bean.UserBean;
import com.yingying.dao.UserDao;

/**
 * @ClassName: AmberBakery
 * @Description:
 * @author chendong
 * @date 2017年3月26日 上午9:01:51
 */
@Service
public class LoginService {
	private static Logger log = LoggerFactory.getLogger(LoginService.class);
	@Resource
	private UserDao userDao;
	
	public UserBean validatelogin(String username, String password) {
		UserBean user = userDao.selectone(username);
		if(user == null) {
			return null;
		}
		String passwordDB = user.getPassWord();
		if(password.equals(passwordDB)) {
			user.setPassWord(null);
			return user;
		}else {
			return null;
		}
	}
	
	public boolean registeruser(String username, String password, String email, String address, String upicpath, String realpath) {
		UserBean user = new UserBean(username, password, email, address, Double.valueOf(0), upicpath);
		boolean result = false; 
		try{
			result = userDao.insert(user);
		}catch (Exception e) {
			log.error("用户名相同");
		}
		return result;
	}
}
